export default function lastModifiedPlugin (schema: any, options: any) {
  schema.add({ lastMod: Date })

  const processFn = function (next: any) {
    this.lastMod = new Date()
    next()
  }

  schema.pre('save', processFn)
    .pre(/^update*/, processFn)

  if (options && options.index) {
    schema.path('lastMod').index(options.index)
  }
}
